﻿using System;
using System.Data;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using AnyOffice.WorkFlowRegex;
using PickListControl;
namespace AnyOffice.general.system.workflow.flow_type
{
    public partial class type_process_autoitem : ModulePage
    {
       
        private int _id;
        private string autoItem = "";
        private int flowid;
        protected PickList pklAutoItem;


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.flowid = (Request.QueryString["flow_id"] == null) ? 0 : int.Parse(Request.QueryString["flow_id"].ToString());
                this.ViewState["FlowId"] = this.flowid;
                bool flag = (Request.QueryString["graph"] != null) ? Convert.ToBoolean(Request.QueryString["graph"].ToString()) : false;
                this.ViewState["IsGraph"] = flag;
                if (flag)
                {
                    this.litButton.Text = "<input type=\"button\" value=\"关闭\" class=\"BigButton\" name=\"back\" onClick=\"window.close();\">";
                }
                else
                {
                    this.litButton.Text = "<input type=\"button\" value=\"返回\" class=\"BigButton\" name=\"back\" onClick=\"history.back();\">";
                }
                this._id = (Request.QueryString["id"] == null) ? 0 : int.Parse(Request.QueryString["id"].ToString());
                this.ViewState["Id"] = this._id;
                FormRegex regex = new FormRegex();
                DataTable table = new FlowFormTypeDao().SelectByFlowId(base.Conn, this.flowid);
                if (table.Rows.Count > 0)
                {
                    regex.HtmlSource = (table.Rows[0]["FormModel"] != DBNull.Value) ? table.Rows[0]["FormModel"].ToString() : "";
                }
                DataTable controlBaseAttribute = regex.GetControlBaseAttribute();
                DataTable table3 = new FlowProcessDao().SelectById(base.Conn, this._id);
                if (table3.Rows.Count > 0)
                {
                    this.litPrcsId.Text = table3.Rows[0]["PrcsId"].ToString();
                    this.autoItem = (table3.Rows[0]["AutoItem"] != DBNull.Value) ? table3.Rows[0]["AutoItem"].ToString() : "";
                    this.autoItem = "," + this.autoItem + ",";
                }
                for (int i = 0; i < controlBaseAttribute.Rows.Count; i++)
                {
                    if ((Convert.ToInt32(controlBaseAttribute.Rows[i]["ControlType"].ToString()) == 5) || (Convert.ToInt32(controlBaseAttribute.Rows[i]["ControlType"].ToString()) == 6))
                    {
                        ListItem item = new ListItem(controlBaseAttribute.Rows[i]["Title"].ToString(), controlBaseAttribute.Rows[i]["Title"].ToString());
                        if (this.autoItem.IndexOf("," + controlBaseAttribute.Rows[i]["Title"].ToString() + ",") >= 0)
                        {
                            this.pklAutoItem.ItemsLeft.Add(item);
                        }
                        else
                        {
                            this.pklAutoItem.ItemsRight.Add(item);
                        }
                    }
                }
            }
            if (this.Page.IsPostBack)
            {
                this._id = Convert.ToInt32(this.ViewState["Id"]);
                foreach (ListItem item2 in this.pklAutoItem.ItemsLeft)
                {
                    this.autoItem = this.autoItem + item2.Value + ",";
                }
                FlowProcessDao dao3 = new FlowProcessDao();
                FlowProcessData data = new FlowProcessData();
                data.Id = this._id;
                data.AutoItem = this.autoItem;
                dao3.SetAutoItem(base.Conn, data);
                base.CloseConn();
                if (Convert.ToBoolean(this.ViewState["IsGraph"].ToString()))
                {
                    if (!this.Page.IsStartupScriptRegistered("SefClose"))
                    {
                        this.Page.RegisterStartupScript("SefClose", "<script>parent.opener.location.reload();\nwindow.close();</script>\n");
                    }
                }
                else
                {
                    Response.Redirect("type_view_list.aspx?flow_id=" + this.ViewState["FlowId"].ToString());
                }
            }
        }
       
    }
}

